package com.ruoyi.test.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.test.domain.MigrationData;
import com.ruoyi.test.service.IMigrationDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 物流Controller
 * 
 * @author ruoyi
 * @date 2024-11-13
 */
@RestController
@RequestMapping("/wuliu/wuliu")
public class MigrationDataController extends BaseController
{
    @Autowired
    private IMigrationDataService migrationDataService;

    /**
     * 查询物流列表
     */
    @PreAuthorize("@ss.hasPermi('wuliu:wuliu:list')")
    @GetMapping("/list")
    public TableDataInfo list(MigrationData migrationData)
    {
        startPage();
        List<MigrationData> list = migrationDataService.selectMigrationDataList(migrationData);
        return getDataTable(list);
    }

    /**
     * 导出物流列表
     */
    @PreAuthorize("@ss.hasPermi('wuliu:wuliu:export')")
    @Log(title = "物流", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MigrationData migrationData)
    {
        List<MigrationData> list = migrationDataService.selectMigrationDataList(migrationData);
        ExcelUtil<MigrationData> util = new ExcelUtil<MigrationData>(MigrationData.class);
        util.exportExcel(response, list, "物流数据");
    }

    /**
     * 获取物流详细信息
     */
    @PreAuthorize("@ss.hasPermi('wuliu:wuliu:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(migrationDataService.selectMigrationDataById(id));
    }

    /**
     * 新增物流
     */
    @PreAuthorize("@ss.hasPermi('wuliu:wuliu:add')")
    @Log(title = "物流", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MigrationData migrationData)
    {
        return toAjax(migrationDataService.insertMigrationData(migrationData));
    }

    /**
     * 修改物流
     */
    @PreAuthorize("@ss.hasPermi('wuliu:wuliu:edit')")
    @Log(title = "物流", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MigrationData migrationData)
    {
        return toAjax(migrationDataService.updateMigrationData(migrationData));
    }

    /**
     * 删除物流
     */
    @PreAuthorize("@ss.hasPermi('wuliu:wuliu:remove')")
    @Log(title = "物流", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(migrationDataService.deleteMigrationDataByIds(ids));
    }
}
